<style scoped>
.totalR {
  float: right;
  margin-right: 8px;
  margin-top: 6px;
  font-size: 14px;
  color: #666;
}
</style>
<!--  -->
<template>
  <div class="system-product-list" v-loading="globalLoading">
    <TipTotal :title="(system.name?system.name+'-':'')+'列表'">
      <div>
        <OperateSystemProductList :system="system" :resetData="resetData" />
      </div>
      <template slot="total">
        <p class="totalR" v-if="total">产品总数：{{total}}</p>
      </template>
    </TipTotal>

    <!-- 查询列表 -->
    <SearchSystemProductList :search="search" :resetData="resetData" :reset="resetSearch" :system="system" />
    <!-- 列表数据展示 -->
    <DataTable ref="systemProductList" :search="search" :dataTotal="dataTotal" :system="system" />
  </div>
</template>

<script>
import TipTotal from '@/components/common/TipTotal.vue'
import OperateSystemProductList from '@/components/main/user/system/product/OperateSystemProductList.vue'
import SearchSystemProductList from '@/components/main/user/system/product/SearchSystemProductList.vue'
import DataTable from '@/components/main/user/system/product/DataTable.vue'
export default {
  created () {
    let query = this.$route.query
    if (!query || !query.sid) {
      this.$message.error('未能获取到正确的数据')
      return
    }
    this.systemId = query.sid
    // 获取系统信息
    this.$post('/system/info', { id: this.systemId }).then((resoponse) => {
      this.system = resoponse
      this.globalLoading = false
      this.$store.dispatch('navPrependNameByPath', { prependName: this.system.name + '-', path: this.$route.fullPath })
    })
  },
  data () {
    return {
      // 全局加载中
      globalLoading: true,
      systemId: 0,
      total: 0,
      // 当前的系统
      system: {},
      // 查询
      search: {
        title: '',
        category: -1,
        isShow: -1,
        isTop: -1,
        releasedAt: [],
        createAt: [],
        slug: -1
      }
    }
  },
  methods: {
    // 设置总数
    dataTotal (total) {
      this.total = '' + total
    },
    // 重置数据
    resetData (obj) {
      if (typeof obj === 'undefined') {
        this.$refs['systemProductList'].resetData()
      } else {
        this.$refs['systemProductList'].resetData(obj)
      }
    },
    // 重置 search
    resetSearch () {
      this.search = {
        title: '',
        category: -1,
        isShow: -1,
        isTop: -1,
        releasedAt: [],
        createAt: [],
        slug: -1
      }
    }
  },
  components: {
    TipTotal,
    OperateSystemProductList,
    SearchSystemProductList,
    DataTable
  }
}

</script>
